package br.unifor.mia.olio;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity(name = "InstanceType")
@Table(name = "IST_INSTANCE_TYPE")

@NamedQueries(value = {
		@NamedQuery(name = "findAllInstanceType", query = "select OBJECT(o) from InstanceType o"),
		@NamedQuery(name = "findByNameInstanceType", query = "select OBJECT(o) from InstanceType o where o.name in (:name)")})
public class InstanceType implements Serializable{

	private static final long serialVersionUID = 1L;

	@Column(name = "IST_id", nullable = false, unique = true)
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name = "IST_name", nullable = false, unique = true)
	private String name;

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}
	

	@Override
	public boolean equals(Object obj){
		
		if(obj != this){
			if(obj instanceof InstanceType){
				InstanceType lInstanceType = (InstanceType) obj;
				
				return lInstanceType.id.equals(id) && lInstanceType.name.equals(name);
				
			}else{
				return false;
			}
		}else{
			return true;
		}
		
		
	}
	
	@Override
	public int hashCode(){
		return id.hashCode() * 7 + name.hashCode();
	}
}
